package Demo6;

public class MyRun implements Runnable {

    private int ticket = 0;

    @Override
    public void run() {
        while (true) {
           if (sellTicket()) break;
        }
    }

    public synchronized boolean sellTicket() {
        if (ticket < 100) {
            try {
                Thread.sleep(100);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            ticket++;
            System.out.println(Thread.currentThread().getName() + ticket);
        } else {
            return true;
        }
        return false;
    }
}
